﻿#region 命名空间

using System.Data.Entity;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using Sharp.Application.Platform;
using Sharp.Domain.PlatformBoundedContext;
using Sharp.Domain.PlatformBoundedContext.MasterDataModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.MasterDataModule.Services;
using Sharp.Domain.PlatformBoundedContext.MessageModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.MessageModule.Services;
using Sharp.Domain.PlatformBoundedContext.OrgModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.OrgModule.Services;
using Sharp.Domain.PlatformBoundedContext.PermissionModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.PersonModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.PersonModule.Services;
using Sharp.Domain.PlatformBoundedContext.PlatformModule.Aggregates;
using Sharp.Domain.PlatformBoundedContext.UserModule.Aggregates;
using Sharp.Domain.Repositories;
using Sharp.Domain.Repository.EF;
using Sharp.Infrastructure;
using Sharp.Infrastructure.Communication;
using Sharp.Infrastructure.Crosscutting;
using Sharp.Infrastructure.Interfaces;
using Sharp.Infrastructure.IoC;
using Sharp.ServiceContracts;

#endregion

namespace Sharp.Services
{
    /// <summary>
    ///     DI container accesor
    /// </summary>
    public static class IoCContainer
    {
        public static void ConfigureContainer()
        {
            /*
             * Add here the code configuration or the call to configure the container 
             * using the application configuration file
             */
            ServiceLocator.RegisterType<DbContext, Entities>();
            ServiceLocator.RegisterType<IRepositoryContext, EntityFrameworkRepositoryContext>(
               new WcfPerRequestLifetimeManager());

            ////-> Unit of Work and repositories


            ServiceLocator.RegisterType<IUserRepository, UserRepository>();
            ServiceLocator.RegisterType<IUserGroupRepository, UserGroupRepository>();
            ServiceLocator.RegisterType<IRoleRepository, RoleRepository>();
            ServiceLocator.RegisterType<IPermissionRepository, PermissionRepository>();
            ServiceLocator.RegisterType<IUserLogRepository, UserLogRepository>();

            ServiceLocator.RegisterType<IGroupRepository, GroupRepository>();
            ServiceLocator.RegisterType<IJobRepository, JobRepository>();
            ServiceLocator.RegisterType<IOrgRepository, OrgRepository>();
            ServiceLocator.RegisterType<IOrgLevelRepository, OrgLevelRepository>();
            ServiceLocator.RegisterType<IOrgForBusinessRepository, OrgForBusinessRepository>();
            ServiceLocator.RegisterType<IOrgForBusinessListRepository, OrgForBusinessListRepository>();

            ServiceLocator.RegisterType(typeof(IEmployeeRepository), typeof(EmployeeRepository));
            ServiceLocator.RegisterType(typeof(IMasterDataRepository), typeof(MasterDataRepository));

            ServiceLocator.RegisterType<IMessageRepository, MessageRepository>();
            ServiceLocator.RegisterType<INoticeRepository, NoticeRepository>();

            ServiceLocator.RegisterType<ISubSystemRepository, SubSystemRepository>();
            ////-> Adapters


            ////-> Domain Service
            ServiceLocator.RegisterType(typeof(IMasterDataService), typeof(MasterDataService));
            ServiceLocator.RegisterType<IPersonService, PersonService>();
            ServiceLocator.RegisterType<Sharp.Domain.PlatformBoundedContext.UserModule.Services.IUserService, Sharp.Domain.PlatformBoundedContext.UserModule.Services.UserService>();
            ServiceLocator.RegisterType<IOrgService, OrgService>();
            ServiceLocator.RegisterType<IMessageService, MessageService>();

            //// Application Service Implementations
            ServiceLocator.RegisterType<IEnterpriseService, EnterpriseServiceImp>(
                new Interceptor<TransparentProxyInterceptor>(),
                new InterceptionBehavior<PolicyInjectionBehavior>(),
                new InterceptionBehavior(new ExceptionLoggingBehavior()));
            ServiceLocator.RegisterType<IUserService, UserServiceImpl>(
                new Interceptor<TransparentProxyInterceptor>(),
                new InterceptionBehavior<PolicyInjectionBehavior>(),
                new InterceptionBehavior(new ExceptionLoggingBehavior()));



            ServiceLocator.RegisterType(typeof(IPlatformService), typeof(PlatformServiceImpl),
                new Interceptor<TransparentProxyInterceptor>(),
                new InterceptionBehavior<PolicyInjectionBehavior>(),
                new InterceptionBehavior(new ExceptionLoggingBehavior())
                );

            ServiceLocator.RegisterType<IBootstrapPlugin, Sharp.Application.Platform.Bootstraper>("A");
            ServiceLocator.RegisterType<IBootstrapPlugin, Sharp.Domain.PlatformBoundedContext.Bootstraper>("B");
        }


    }
}